<template>
  <div class="home">
    <el-container>
      <el-header>
        <div class="left">
          <i class="el-icon-s-home"></i>
          <span> 课程选课系统</span>
        </div>
        <div class="right">
          <i class="el-icon-full-screen"></i>
          <el-avatar :size="32"
            src="https://ts1.tc.mm.bing.net/th/id/OIP-C.11hzv_skbfdaFBxwkTRVdAAAAA?w=186&h=211&c=8&rs=1&qlt=70&o=7&cb=thws5&dpr=1.3&pid=3.1&rm=3"></el-avatar>
          <el-dropdown @command="logout">
            <span class="el-dropdown-link">
              下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>退出登录</el-dropdown-item>
            </el-dropdown-menu>

          </el-dropdown>
        </div>

      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu :default-active="$route.path" background-color="#324157" text-color="#fff" router>
            <el-menu-item index="/index">
              <span slot="title">首页</span>
            </el-menu-item>
            <el-menu-item v-for="item in $store.state.user.roles" :key="item.children[0].path"
              :index="item.children[0].path">
              <span slot="title">{{ item.children[0].meta.title }}</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 子路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { logout } from '@/api/user';
export default {
  name: 'HomeView',
  methods: {
    logout() {
      logout().then(res => {
        this.$store.commit('user/updateLoggedIn', false)
        this.$store.commit('user/updateUserType', 0)
        this.$store.commit('user/updateRoles', [])
        this.$store.commit('user/updatepermission', 0)
        // 跳转
        this.$router.push('/login')
      })
    },
  },
  mounted() {
    // console.log(this.$store.state.user.roles);
  }
}
</script>
<style lang="scss" scoped>
.home {
  height: 100%;

  .el-container {
    height: 100%;

    .el-header {
      background-color: #242F42;
      color: #fff;
      line-height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .left {
        font-size: 22px;
      }

      .right {
        width: 150px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 24px;

        .el-dropdown-link {
          color: #fff;
        }
      }
    }

    .el-aside {
      background-color: #324157;

      .el-menu {
        border-right: none;
      }
    }
  }

  .el-main {
    padding: 0;
  }
}
</style>